package com.shop2cn.iapi.sqoptrade.service;

import org.json.JSONException;
import org.json.JSONObject;

import com.shop2cn.iapi.sqoptrade.resp.PlaceOrderResp;
import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.utils.EnvSetup;

/**
 * 创建订单(新)接口Call FreeMaker Template自动生成代码
 */
public class PlaceOrderByApportionedAmountCall extends PlaceOrderCall {
	private static String opurl = "placeorder/placeOrderByApportionedAmount";

	public PlaceOrderByApportionedAmountCall() {
//		super(EnvSetup.getSystemUrl("operate2_iapi"), opurl, "POST", "JSON");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Accept",
				"text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	// get data
	public JSONObject getData() {
		JSONObject data = null;
		try {
			data = (JSONObject) new JSONObject(getReturnData()).get("data");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return data;
	}

	// code
	public int getCode() {
		Integer code = null;
		try {
			code = new JSONObject(getReturnData()).optInt("code");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return code;
	}

	// bcode
	public int getBcode() {
		Integer code = null;
		try {
			code = new JSONObject(getReturnData()).optInt("bcode");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return code;
	}

	// code
	public String getMsg() {
		String msg = null;
		try {
			msg = new JSONObject(getReturnData()).optString("msg");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return msg;
	}
	
	// errorCodeValue
	public int getErrorCodeValue() {
		Integer errorCodeValue = null;
		try {
			errorCodeValue = this.getData().optInt("errorCodeValue");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return errorCodeValue;
	}

	// PlaceOrderResp
	public PlaceOrderResp getPlaceOrderResp() {

		return (PlaceOrderResp) FormatUtil.GSONToObject(getData().toString(),
				PlaceOrderResp.class);
	}
}
